package com.sangeng.controller;

import com.sangeng.domain.ResponseResult;
import com.sangeng.domain.entity.Article;
import com.sangeng.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

//    测试接口使用能通过专用：
//    @GetMapping("/list")
//    public List<Article> test(){
//        return articleService.list();
//
//    }

    @GetMapping("/hotArticleList")
    public ResponseResult hotArticleList(){
//        查询热门文章，分装成ResponseResult返回
        ResponseResult result =articleService.hotArticleList();
        return result;
    }

//    /lujing/1  加注解  @PathVariable
//    请求体中获得 /1   加注解 @RequestBody
    @GetMapping("/articleList")
    public ResponseResult articleList(Integer pageNum,Integer pageSize,Long categoryId){
        return articleService.articleList(pageNum,pageSize,categoryId);

    }

    /*
    * 跳转到文章内容页面
    * */
    @GetMapping("/{id}")
    public ResponseResult getArticleDetail(@PathVariable("id") Long id){
        return articleService.getArticleDetail(id);

    }

    /*
    * 更新浏览次数
    * */
    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable("id") Long id){
        return articleService.updateViewCount(id);
    }
}
